import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  ManyToOne,
  JoinColumn,
} from 'typeorm';
import { TArticle } from './article.entity';

@Entity()
export class TArticleComment {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ type: 'bigint', name: 'article_id', comment: '关联文章ID' })
  articleId: number;

  @ManyToOne(() => TArticle, (article) => article.comments, {
    onDelete: 'CASCADE',
  })
  @JoinColumn({ name: 'article_id' })
  article: TArticle;

  @Column({ type: 'bigint', name: 'pid', comment: '父评论ID', default: 0 })
  pid: number;

  @Column({ type: 'varchar', length: 255, name: 'author', comment: '评论作者' })
  author: string;

  @Column({ type: 'text', name: 'content', comment: '评论内容' })
  content: string;

  @Column({
    type: 'datetime',
    name: 'created_at',
    comment: '评论时间',
    default: () => 'CURRENT_TIMESTAMP',
  })
  createdAt: string;
}
